package com.zbkj.dal.base.enums;

import com.zbkj.dal.base.enums.show.EnumInterface;
import com.zbkj.dal.common.exception.CrmebException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

@AllArgsConstructor
public enum OrderType implements EnumInterface<Integer> {

    /**
     * 订单子阶段类型
     */

    // ----------------- 承享订单 -----------------

    PURCHASE(0, "购买订单"),
    RENT(10, "承享订单"),


    SHARED(20, "供享订单"),

    RECOMMEND_REWARD(30, "拉新奖励"),
    WHOLE_WORLD_FIND(40, "全球找货"),
    RECYCLE_SALE(50, "回收寄卖"),
    REPAIR_UPKEEP(60, "回收保养");;

    @Getter
    private final Integer code;
    @Getter
    private final String message;

    public Integer code() {
        return getCode();
    }

    public String desc() {
        return getMessage();
    }

    public static OrderType of(String name) {
        for (OrderType value : OrderType.values()) {
            if (StringUtils.equals(value.name(), name)) {
                return value;
            }
        }
        throw new CrmebException("不支持的类型");
    }

    public static OrderType of(Integer code) {
        for (OrderType value : OrderType.values()) {
            if (Objects.equals(value.code, code)) {
                return value;
            }
        }
        throw new CrmebException("不支持的类型");
    }

    // 判断是否是承享订单
    public static boolean isRent(Integer type) {
        return RENT.code.equals(type);
    }

    // 判断是否是买入订单
    public static boolean isPurchase(Integer type) {
        return PURCHASE.code.equals(type);
    }



}
